//
//  TitleLabel+TextFieldView.m
//  YIJU2.0-HD
//
//  Created by URANUS on 16/5/12.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "TitleLabelAndTextFieldView.h"
#import "Macro.h"
#import "Masonry.h"

@interface TitleLabelAndTextFieldView()

@property (nonatomic, strong)UILabel *titleLabel;

@property (nonatomic, strong)UITextField *messageTextField;
@end

@implementation TitleLabelAndTextFieldView
#pragma mark - init
- (instancetype)initWithBlockMyEditText:(TextFieldString)textBlock {
    if (self = [super init]) {
        [self setupConstraints];
        self.MyTextString = textBlock;
        self.MyTextString(_messageTextField);
    }
    return self;
}

#pragma mark - private
- (void)setupConstraints {

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(TenOffsetViewMargin);
        make.left.equalTo(self.mas_left).offset(TenOffsetViewMargin + FiveOffsetViewMargin);
        make.width.equalTo(self.mas_width).multipliedBy(1/5.0f);
        make.bottom.equalTo(self.mas_bottom).offset(-TenOffsetViewMargin);
    }];
    
    [self.messageTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_top);
        make.left.equalTo(self.titleLabel.mas_right).offset(TenOffsetViewMargin);
        make.width.equalTo(self.mas_width).multipliedBy(2/3.2f);
        make.bottom.equalTo(self.titleLabel.mas_bottom);
    }];
    
    
}

#pragma mark - getters
- (UILabel *)titleLabel {
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.textColor = kTextColor;
        _titleLabel.font = kTitle_Font;
        _titleLabel.text = self.TitleString;
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UITextField *)messageTextField {
    if (_messageTextField == nil) {
        _messageTextField = [[UITextField alloc] init];
        _messageTextField.font = kTitle_Font;
        _messageTextField.textColor = kTextColor;
        _messageTextField.layer.cornerRadius = 3.0f;
        _messageTextField.layer.masksToBounds = YES;
        _messageTextField.layer.borderColor = [UIColor colorWithWhite:0.702 alpha:1.000].CGColor;
        _messageTextField.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_messageTextField];
    }
    return _messageTextField;
}

#pragma mark - setter
- (void)setTitleString:(NSString *)TitleString {
    
    _TitleString = TitleString;
    _titleLabel.text = TitleString;
}

@end
